﻿using System;
using RpcHelper;
using RpcModularModel.Identity.Msg;
using RpcModularModel.Resource;
using SqlExecHelper;
using Wedonek.RpcStore.Service.DAL;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.Collect
{

        internal class IdentityProwerCollect : BasicCollect<IdentityProwerDAL>, IIdentityProwerCollect
        {

                public string[] GetProwers (Guid appId, string systemType, ResourceType type)
                {
                        return base.BasicDAL.GetProwers (appId, systemType, type);
                }

                public string[] GetSystemType (Guid appId)
                {
                       return base.BasicDAL.GetSystemType(appId);
                }

                public void Sync (IdentityProwerList add)
                {
                        using (ITransaction tran = base.GetCollect<ITransaction> ())
                        {
                                base.BasicDAL.Clear (add.AppId);
                                base.BasicDAL.Adds (add);
                                tran.Commit ();
                        }
                        new RefreshIdentityPrower
                        {
                                AppId = add.AppId,
                                SystemType = add.Values.Distinct(a=>a.SystemType)
                        }.SyncSend ();
                }
        }
}
